/**
 * Copyright:  Copyright (c) 2013
 *
 * @FileName		: PrimeCostAction.java
 * @PageName		: 제조원가, 제조경비, 제품 수익 비교
 * @Date			: 오후 5:27:54
 * @LastModifier	: 최경민
 * @LastModifyDate	: 
 * @LastModifier	: 
 * Change history	:
 */
package com.pulp.management.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.pulp.management.model.ManagementInfo;
import com.pulp.management.service.ManagementService;

/**
 * @author Administrator
 * 
 */
public class PrimeCostAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(PrimeCostAction.class);

	private String errorCode = "";
	private String page;
	private String total;

	private List<ManagementInfo> primeCostYear = null;
	private List<ManagementInfo> primeCostMonth = null;
	private List<ManagementInfo> primeCostFactoryCostYear = null;
	private List<ManagementInfo> primeCostFactoryCostMonth = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		PrimeCostAction.logger = logger;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return the page
	 */
	public String getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @return the total
	 */
	public String getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(String total) {
		this.total = total;
	}

	public String execute() throws Exception {
		System.out.println("PrimeCostAction===================");
		try {
			HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			ManagementService service = (ManagementService) wac.getBean("managementService");
			
			primeCostYear = (List<ManagementInfo>) service.getPrimeCostYear();
			primeCostMonth = (List<ManagementInfo>) service.getPrimeCostMonth();
			primeCostFactoryCostYear = (List<ManagementInfo>) service.getPrimeCostFactoryCostYear();
			primeCostFactoryCostMonth = (List<ManagementInfo>) service.getPrimeCostFactoryCostMonth();
			

			request.setAttribute("primeCostYear", primeCostYear);
			request.setAttribute("primeCostMonth", primeCostMonth);
			request.setAttribute("primeCostFactoryCostYear", primeCostFactoryCostYear);
			request.setAttribute("primeCostFactoryCostYear", primeCostFactoryCostYear);

		} catch (Exception e) {
			REQUEST_RESULT = "FAILED";
			e.printStackTrace();
		}
		return REQUEST_RESULT;
	}
}
